<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>CMS Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script>
function changeStatus(id, status, type){
    window.location.href="../action/changeStatus.php?i="+id+"&t="+type+"&s="+status;
}

function search(){
    window.location.href="administration.php?key="+document.getElementById("key").value;
}
</script>
<style media="all" type="text/css">
@import "../css/all.css";
</style>
</head>
<body>
<div id="main">

  <?php
        $page = 1;
        include "header.php";  
        include "../service/userService.php";
  ?>
  
  <div id="middle">
    <div id="left-column">
      <h3>Chức năng</h3>
      <ul class="nav">
        <li>
        <?php
        //Admin function
        if($loggedInUser[2] == 1){
                echo "<a href='../admin/administration.php'>Quản lí thông tin cho admin</a>";
        }
        ?>
        </li>
      </ul>
       
      </div>
    <div id="center-column">
      <div class="top-bar">
        <h1>User Management</h1>
      </div>
      <br />
      <div class="select-bar">
        <label>
        <input id="key" type="text" name="textfield" />
        </label>
        <label>
        <input type="button" name="searchbtn" value="Search" onclick="search();" />
        </label>
      </div>
      <div class="table"> <img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" /> <img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
        <table class="listing" cellpadding="0" cellspacing="0">
          <tr>
            <th class="first" width="177">Username</th>
            <th>User Type</th>
            <th>Status</th>
            <th class="last">Reset Password</th>
          </tr>
          <?php
          if(isset($_GET["key"])){
            $keyword = $_GET["key"];
          }else{
            $keyword = "";
          }
            $mods = getModStatus($keyword);
            while($mod = mysql_fetch_array($mods)){
          ?>
              <tr>
                <td class="first style1"><?php echo $mod["USER_NAME"]; ?></td>
                <td>
                <?php 
                    $type = $mod["USER_TYPE"];
                    if ($type == 1)
                        echo "Administrator";
                    if ($type == 2)
                        echo "Moderator";
                    if ($type == 3)
                        echo "Company";
                    if ($type == 4)
                        echo "Normal User";                         
                ?>
                </td>
                <td>
                <select id="statusCmbx" onchange="changeStatus(<?php echo $mod["USER_ID"]; ?>, this.value, <?php echo $mod["USER_TYPE"]; ?>);">
                    <option value="1" <?php echo $mod["STATUS"] == 1?"selected=selected":""; ?>>Active</option>
                    <option value="0" <?php echo $mod["STATUS"] == 0?"selected=selected":""; ?>>Inactive</option>
                </select>
                </td>
                <td class="last"><a href="../action/resetP.php?n=<?php echo $mod["USER_ID"]; ?>&t=<?php echo $mod["USER_TYPE"]; ?>">Reset Password</a></td>
              </tr>
          <?php
            }
          ?>
          
          <?php
            $mods = getCompanyStatus($keyword);
            while($mod = mysql_fetch_array($mods)){
          ?>
              <tr>
                <td class="first style1"><?php echo $mod["USER_NAME"]; ?></td>
                <td>
                <?php 
                    $type = $mod["USER_TYPE"];
                    if ($type == 1)
                        echo "Administrator";
                    if ($type == 2)
                        echo "Moderator";
                    if ($type == 3)
                        echo "Company";
                    if ($type == 4)
                        echo "Normal User";                        
                ?>
                </td>
                <td>
                <select id="statusCmbx" onchange="changeStatus(<?php echo $mod["USER_ID"]; ?>, this.value, <?php echo $mod["USER_TYPE"]; ?>);">
                    <option value="1" <?php echo $mod["STATUS"] == 1?"selected=selected":""; ?>>Active</option>
                    <option value="0" <?php echo $mod["STATUS"] == 0?"selected=selected":""; ?>>Inactive</option>
                </select>
                </td>
                <td class="last"><a href="../action/resetP.php?n=<?php echo $mod["USER_ID"]; ?>&t=<?php echo $mod["USER_TYPE"]; ?>">Reset Password</a></td>
              </tr>
          <?php
            }
          ?>
          
          <?php
            $mods = getNormalUserStatus($keyword);
            while($mod = mysql_fetch_array($mods)){
          ?>
              <tr>
                <td class="first style1"><?php echo $mod["USER_NAME"]; ?></td>
                <td>
                <?php 
                    $type = $mod["USER_TYPE"];
                    if ($type == 1)
                        echo "Administrator";
                    if ($type == 2)
                        echo "Moderator";
                    if ($type == 3)
                        echo "Company";
                    if ($type == 4)
                        echo "Normal User";                        
                ?>
                </td>
                <td>
                <select id="statusCmbx" onchange="changeStatus(<?php echo $mod["USER_ID"]; ?>, this.value, <?php echo $mod["USER_TYPE"]; ?>);">
                    <option value="1" <?php echo $mod["STATUS"] == 1?"selected=selected":""; ?>>Active</option>
                    <option value="0" <?php echo $mod["STATUS"] == 0?"selected=selected":""; ?>>Inactive</option>
                </select>
                </td>
                <td class="last"><a href="../action/resetP.php?n=<?php echo $mod["USER_ID"]; ?>&t=<?php echo $mod["USER_TYPE"]; ?>">Reset Password</a></td>
              </tr>
          <?php
            }
          ?>
        </table>
        <!--
        <div class="select"> <strong>Other Pages: </strong>
          <select>
            <option>1</option>
          </select>
        </div>
        -->
      </div>
      <div class="table"> <img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" /> <img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
        
      </div>
    </div>
    <div id="right-column"> <strong class="h">Ghi chú</strong>
      <div class="box">
        Quản lí danh sách thành viên và moderator. Enable hay Disable account và reset password.
      </div>
    </div>
  </div>
  <?php include "footer.php";?>
</div>
</body>
</html>
